package com.colis.quartz.consumer.sms;

import com.colis.quartz.annotation.RMpController;
import com.colis.quartz.common.base.RestResult;
import com.colis.quartz.common.enumerate.QuartzStatusEnum;
import com.colis.quartz.module.sms.QuartzTask;
import com.colis.quartz.provider.sms.service.impl.QuartzTaskServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p> 描述：定时任务  前端控制器 定时任务时间表达式在线生成： http://www.bejson.com/othertools/cron/ </p>
 *
 * @author wlp
 * @version 1.0.0
 * @date 2022/1/13 10:41
 */
@Api(tags = "定时任务模块API")
@RMpController("quartzTask")
public class QuartzTaskController {

    @Resource
    private QuartzTaskServiceImpl quartzTaskService;

    @PostMapping("startJob")
    @ApiOperation(value = "测试运行定时任务", httpMethod = "POST")
    public RestResult<String> startJob() {
        //**10秒执行一次
        LocalDateTime now = LocalDateTime.now();
        QuartzTask quartzTask = new QuartzTask()
                .setQuartzStatus(QuartzStatusEnum.NORMAL)
                .setParams("大吉大利，今晚吃鸡")
                .setQuartzCron("*/10 * * * * ?")
                .setQuartzName("测试运行定时任务")
                .setQuartzType(1)
                .setTargetBean("com.colis.quartz.common.task.MyTask")
                .setTargetMethod("runTask");
        quartzTask.setCreateTime(now).setModifyTime(now);
        quartzTaskService.saveJob(quartzTask);
        return RestResult.success("成功");
    }
}
